//
//  DataSummaryBloodPressureCell.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/24.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import UIKit
import Charts

class DataSummaryBloodPressureCell: DataSummaryBloodOxygenCell {
    
    override var dataSets: [LineChartDataSet] {
        [sbpDataSet, dbpDataSet]
    }
    
    override func update(vm: DataSummaryCellViewModel, data: Any?) {
        super.update(vm: vm, data: data)
        
        // TODO: 血压数据
        valueLabel.text = "--"
    }
    
    // 收缩压
    private lazy var sbpDataSet: LineChartDataSet = {
        // TODO: 准确数据
        let entries = (0...8)
            .map { i in
                ChartDataEntry(x: Double(i), y: Double((90...200).randomElement()!))
            }
        let dataSet = LineChartDataSet(entries: entries, label: "sbp")
        setupDataSet(dataSet)
        dataSet.fill = ColorFill(color: HEX(0xFF716A, alpha: 0.1)!)
        return dataSet
    }()
    
    // 舒张压
    private lazy var dbpDataSet: LineChartDataSet = {
        // TODO: 准确数据
        let entries = (0...8)
            .map { i in
                ChartDataEntry(x: Double(i), y: Double((50...100).randomElement()!))
            }
        let dataSet = LineChartDataSet(entries: entries, label: "dbp")
        setupDataSet(dataSet)
        dataSet.fill = ColorFill(color: .white)
        return dataSet
    }()
    
    override func setupDataSet(_ set: LineChartDataSet) {
        super.setupDataSet(set)
        
        set.circleHoleColor = HEX(0xDC4F48)
        set.setColor(HEX(0xDC4F48)!)
    }
}
